#ifndef __FS_H_
#define __FS_H_

#include "types.h"

#define FILE_TABLE_SIZE 10
#define FNAME_LENGTH 30
// current working directory
#define AT_FDCWD -100

// openat flags
#define O_RDONLY 0x000
#define O_WRONLY 0x001
#define O_RDWR 0x002 // 可读可写
//#define O_CREATE 0x200
#define O_CREATE 0x40
#define O_DIRECTORY 0x0200000

#define ROOT_DIR_FD 3

enum file_type
{
      UNUSED, DEVICE, FILE, DIRECTORY
};

/* @brief: stores file info
 */
struct file_info {
	enum file_type type;
	char fname[FNAME_LENGTH];
	uint8 attributes;
	uint32 first_clus_num;
	uint32 size;
};


extern struct file_info file_table[];
// current directory
extern struct file_info *cur_dir;
void fs_init();
int fs_openat(int fd, char *filename, int flags, int mode);
struct file_info *alloc_file_info();
int fs_read(int fd, void *buf, uint32 size);
int fs_close(int fd);

#endif
